#员工管理模块的接口对象层
import  requests

class IhrmEmpCrud(object):

    #添加员工
    #header中的令牌是变化的
    @classmethod
    def add_emp(cls,header,json_data):
        url = "http://ihrm2-test.itheima.net/api/sys/user"
        resp = requests.post(url=url, headers=header, json=json_data)
        return resp

    # 查询员工
    @classmethod
    def query_emp(cls,emp_id,header):
        url = "http://ihrm2-test.itheima.net/api/sys/user/"+emp_id
        resp = requests.get(url=url, headers=header)
        return resp

    # 修改员工
    @classmethod
    def modify_emp(cls,emp_id,header,modify_data):
        url = "http://ihrm2-test.itheima.net/api/sys/user/"+emp_id
        resp = requests.put(url=url, headers=header, json=modify_data)
        return resp

    # 删除员工
    @classmethod
    def delete_emp(cls,emp_id,header):
        url = "http://ihrm2-test.itheima.net/api/sys/user/"+emp_id
        resp = requests.delete(url=url, headers=header)
        return resp


if  __name__ == "__main__":
        header={"Content-Type":"application/json","Authorization":"Bearer 5f031481-f86d-4877-b0bb-15889eeda5ce"}
        data_add = {
"username":"micky",
"mobile":"15100000049",
"workNumber":"9527"
}
        resp = IhrmEmpCrud.add_emp(header,data_add)
        print("添加：",resp.json())

        emp_id = "1469566449784717312"
        resp = IhrmEmpCrud.query_emp(emp_id,header)
        print("查询：",resp.json())

        data = {"username": "12"}
        resp = IhrmEmpCrud.modify_emp(emp_id,header,data)
        print("修改：",resp.json())

        resp = IhrmEmpCrud.delete_emp(emp_id, header)
        print("删除：",resp.json())



